package com.young.springdemo.service.statePattern;
//受限状态
public class RestrictedStateAccountState extends AccountState {

    public RestrictedStateAccountState(AccountState accountState) {
        this.account = accountState.account;
    }

    public RestrictedStateAccountState(Account account){
        this.account = account;
    }

    //存款
    @Override
    public void deposit(double amount) {
        System.out.println(this.account.getOwner()+"存款"+amount);
        this.account.setBalance(account.getBalance()+amount);
        stateCheck();
    }
        //取款
    @Override
    public void withdraw(double amount) {
        /*System.out.println(this.account.getOwner()+"取款"+amount);
        this.account.setBalance(account.getBalance()-amount);
        stateCheck();*/
        System.out.println("受限,不允许取款...");
    }

    @Override
    public void computerInterest() {
        System.out.println("计算利息");
    }

    @Override
    public void stateCheck() {
        if (this.account.getBalance() > 0 ){
            this.account.setState(new NormalAccountState(this));
            System.out.println("切换为正常用户");
        }else if (account.getBalance() > -2000){
            this.account.setState(new OverDraftAccountState(this));
            System.out.println("切换为透支状态");
        }
    }
}
